<?php
/*
    |--------------------------------------------------------------------------
    | Application Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register all of the routes for an application.
    | It's a breeze. Simply tell Laravel the URIs it should respond to
    | and give it the Closure to execute when that URI is requested.
    |
    */

if (Session::get('lang') && Session::get('lang') !=  App::getLocale()) {
    App::setLocale(Session::get('lang'));
}

Route::get('language/{lang}',
    array(
        'as'    => 'language.select',
        'uses'  => 'LanguageController@select'
    )
);

Route::when('*', 'csrf', array('post', 'put', 'delete'));
/**
 * Admin
 */
$admin = Config::get('constants.PACKAGE_ADMIN').'/'.Config::get('constants.ADMIN');

Route::filter('auth', function() {
    if (!Auth::check()) {
        return Redirect::to('dtu/admin/login');
    }
});

Route::get($admin.'/login', array('as' => 'login',  'uses' => 'UserController@login'));
Route::post($admin.'/login', array('as' => 'login', 'uses' => 'UserController@login'));

/* Home */
Route::group(array('prefix' => $admin, 'before' => 'auth'), function() {
    Route::get('/', array('as'=> 'dtu/admin', 'uses' => 'HomeAdminController@index'));
});

Route::get('dtu', function() {
    return Redirect::route('dtu/admin');
});

/* User */
Route::group(array('prefix' => $admin.'/user' ,'before' => 'auth'), function() {
    Route::get('/', array('as' => 'user', 'uses' => 'UserController@index'));
    Route::get('profile', array('as' => 'profile', 'uses' => 'UserController@show'));
    Route::get('logout', array('as'  => 'logout', 'uses'  => 'UserController@logout'));
    Route::get('create', array('as'  => 'create', 'uses'  => 'UserController@create'));
    Route::post('store', array('as'  => 'store', 'before' => 'csrf', 'uses'  => 'UserController@store'));
    Route::get('edit/{id}', array('as' => 'edit', 'uses'  => 'UserController@update'));
    Route::get('delete/{id}', array('as' => 'delete', 'uses' => 'UserController@destroy'));
    Route::get('view/{id}', array('as' => 'view', 'uses' => 'UserController@view'));
});

/* Product */
Route::group(array('prefix' => $admin.'/product' ,'before' => 'auth'), function() {
    Route::get('/', array('as'  => 'product', 'uses' => 'ProductController@index'));
    Route::post('/', array('as' => 'product', 'uses' => 'ProductController@index'));
    Route::post('upload', array('as' => 'upload', 'uses' => 'UploadController@upload'));
    Route::get('create', array('as' => 'product/create',  'uses'  => 'ProductController@create'));
    Route::post('store', array('as' => 'product/store',  'before' => 'csrf', 'uses' => 'ProductController@store'));
    Route::get('view/{id}', array('as' => 'product/view', 'uses'  => 'ProductController@show'));
    Route::get('edit/{id}', array('as' => 'product/edit', 'uses'  => 'ProductController@edit'));
    Route::get('destroy/{id}', array('as' => 'product/delete', 'uses' => 'ProductController@destroy'));
    Route::get('updateStatus', array('as' => 'product/updateStatus', 'uses' => 'ProductController@updateStatus'));
});

/* Category */
Route::group(array('prefix' => $admin.'/category','before' => 'auth'), function() {
    Route::get('/', array('as' => 'category', 'uses' => 'CategoryController@index'));
    Route::post('/', array('as' => 'category', 'uses' => 'CategoryController@index'));
    Route::get('create', array('as' => 'category/create',  'uses'  => 'CategoryController@create'));
    Route::post('store', array('as' => 'category/store',  'before' => 'csrf', 'uses' => 'CategoryController@store'));
    Route::get('view/{id}', array('as' => 'category/view', 'uses'  => 'CategoryController@show'));
    Route::get('edit/{id}', array('as' => 'category/edit', 'uses'  => 'CategoryController@edit'));
    Route::get('destroy/{id}', array('as' => 'category/delete', 'uses' => 'CategoryController@destroy'));
    Route::get('updateStatus', array('as' => 'category/updateStatus', 'uses' => 'CategoryController@updateStatus'));
});

/* Orders */
Route::group(array('prefix' => $admin.'/orders','before' => 'auth'), function() {
    Route::get('/', array('as' => 'orders', 'uses' => 'OrdersController@index'));
    Route::post('/', array('as' => 'orders', 'uses' => 'OrdersController@index'));
    Route::get('create', array('as' => 'orders/create',  'uses'  => 'OrdersController@create'));
    Route::post('store', array('as' => 'orders/store',  'before' => 'csrf', 'uses' => 'OrdersController@store'));
    Route::get('view/{id}', array('as' => 'orders/view', 'uses'  => 'OrdersController@show'));
    Route::get('edit/{id}', array('as' => 'orders/edit', 'uses'  => 'OrdersController@edit'));
    Route::get('destroy/{id}', array('as' => 'orders/delete', 'uses' => 'OrdersController@destroy'));
    Route::get('updateStatus', array('as' => 'orders/updateStatus', 'uses' => 'OrdersController@updateStatus'));
});

/* Orders */
Route::group(array('prefix' => $admin.'/company','before' => 'auth'), function() {
    Route::get('/', array('as' => 'company', 'uses' => 'CompanyController@index'));
});